<?php
namespace api\controllers;

use Yii;
use yii\rest\ActiveController;
use yii\data\ActiveDataProvider; 
use api\models\Ret;
use yii\helpers\ArrayHelper;
use yii\filters\auth\QueryParamAuth;
use common\models\Account;


class SuperstarController extends ActiveController
{
    public $modelClass = 'common\models\Superstar';
    
    public function behaviors(){
      return ArrayHelper::merge(parent::behaviors(), [
          'authenticatior' => [
              'class' => QueryParamAuth::className()
          ]
      ]); 
    }
    public function actions(){
        $action= parent::actions(); // TODO: Change the autogenerated stub
        unset($action['index']);
        // unset($action['create']);
        // unset($action['update']);
        // unset($action['delete']);
    }
    public function actionIndex()
    {
        $token = Yii::$app->request->get("access-token");
        $accM = new Account();
        $acc = $accM->getAccountByToken($token);
        $modelClass = $this->modelClass;
        $query = $modelClass::find()->where('account_id='.$acc['account_id']);
        $res = new ActiveDataProvider([
          'query' => $query,
        ]);
        return  new Ret(1,'获取成功',$res->getModels());
        
    }

    
}
